package com.letv.whatslive.model.convert;

import com.letv.whatslive.common.utils.ObjectUtils;
import com.letv.whatslive.model.ActivityCategory;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by Administrator on 2016/3/7.
 */
public class ActivityCategoryConvert {
    public static DBObject castActivityCategoryToDBObject(ActivityCategory activityCategory) {
        DBObject dbo = new BasicDBObject();
        if (activityCategory.getId() != null) {
            dbo.put("_id", activityCategory.getId());
        }
        dbo.put("categoryCode", ObjUtils.ifNull(activityCategory.getCategoryCode(), ""));
        dbo.put("categoryName", ObjUtils.ifNull(activityCategory.getCategoryName(), ""));
        dbo.put("categoryUpCode", ObjUtils.ifNull(activityCategory.getCategoryUpCode(), ""));
        return dbo;
    }
    public static ActivityCategory castDBObjectToActivityCategory(DBObject dbObject){
        if(dbObject!=null){
            ActivityCategory activityCategory=new ActivityCategory();
            activityCategory.setId(ObjectUtils.toLong(dbObject.get("_id")));
            activityCategory.setCategoryCode(ObjectUtils.toString(dbObject.get("categoryCode")));
            activityCategory.setCategoryName(ObjectUtils.toString(dbObject.get("categoryName")));
            activityCategory.setCategoryUpCode(ObjectUtils.toString(dbObject.get("categoryUpCode")));
            return activityCategory;
        }else{
            return null;
        }
    }
}
